package com.solo.eggsolo.controller;
/**
 * 
 * @author Yu
 *
 */

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import com.solo.eggsolo.common.bean.JsonResult;
import com.solo.eggsolo.service.AdminService;
import com.solo.eggsolo.service.UserService;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;

@RestController
@Api(tags = "登录模块")
public class LoginController {
	
	@Autowired
	private UserService userService;
	
	@Autowired
	private AdminService adminService;
	
	@ApiOperation("用户登录接口")
	@RequestMapping(value= "/login", method = {RequestMethod.POST})
	public JsonResult login(String username,String password) {
		
		JsonResult result = new JsonResult(500,Boolean.FALSE,"登录失败");
		String token = userService.login(username, password);
		if(token != null) {
			result = new JsonResult(200,Boolean.TRUE,"登录成功",token);
			return result;
		}
		return result;
	}
	
	@ApiOperation("管理员登录接口")
	@RequestMapping(value= "/adminLogin", method = {RequestMethod.POST})
	public JsonResult adminLogin(String username,String password) {
		
		JsonResult result = new JsonResult(500,Boolean.FALSE,"登录失败");
		String token = adminService.login(username, password);
		if(token != null) {
			result = new JsonResult(200,Boolean.TRUE,"登录成功",token);
			return result;
		}
		return result;
	}

}
